package com.sgb.kjwl.viewmodel.packers;

import androidx.databinding.ObservableField;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.packers.PackersMapEntity;
import com.sgb.kjwl.model.entity.transport.MapLongAndLatEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.packers.PackersMapActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
*@author 毁灭霸者
*@date 2020/7/15
*description:
*/
public class PackersMapModel extends BaseViewModel {
    public ObservableField<Map<String,Object>> map = new ObservableField<>(new HashMap<>());
    private PackersMapActivity activity;
    private HomeRepertory repertory;

    public PackersMapModel(PackersMapActivity activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void getLocationModel() {
        APIManager.getInstance().getDriverAPI().getLocationLL(repertory.getAreaCode(),repertory.getAreaCode(),"","").enqueue(new Callback<BaseEntity<MapLongAndLatEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<MapLongAndLatEntity>> call, Response<BaseEntity<MapLongAndLatEntity>> response) {
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(AppConstant.REQEUST_SECCUESS)) {
                    activity.showLocation(response.body().getData());
                }
            }
            @Override
            public void onFailure(Call<BaseEntity<MapLongAndLatEntity>> call, Throwable t) {
            }
        });
    }

    public void getWorkList() {
        APIManager.getInstance().getPackerAPI().getPackersMapWorkList(repertory.getAreaCode())
                .enqueue(new Callback<BaseEntity<List<PackersMapEntity>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<List<PackersMapEntity>>> call, Response<BaseEntity<List<PackersMapEntity>>> response) {
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(AppConstant.REQEUST_SECCUESS)) {
                            activity.showWorkList(response.body().getData());
                        }
                    }

                    @Override
                    public void onFailure(Call<BaseEntity<List<PackersMapEntity>>> call, Throwable t) {

                    }
                });
    }

    public void getPackerList() {
        APIManager.getInstance().getPackerAPI().getPackersMapTeamList(repertory.getAreaCode())
                .enqueue(new Callback<BaseEntity<List<PackersMapEntity>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<List<PackersMapEntity>>> call, Response<BaseEntity<List<PackersMapEntity>>> response) {
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(AppConstant.REQEUST_SECCUESS)) {
                            activity.showTeamList(response.body().getData());
                        }
                    }

                    @Override
                    public void onFailure(Call<BaseEntity<List<PackersMapEntity>>> call, Throwable t) {

                    }
                });
    }
}
